home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
EnigmA Amiga Run 1996 April
/
EnigmA AMIGA RUN 06 (1996)(G.R. Edizioni)(IT)[!][issue 1996-04][Skylink CD V].iso
/
progs
/
editor
/
write-ed
/
rexx
/
define.wrx
< prev
next >
Wrap
Text File
|
1995-05-01
|
7KB
|
262 lines
/* Easy handling of defines
*
* © 1993 by MGR-Software, Asgard
* written 23/09/93 by Lars Hanke
* contact: mgr@asgard.bo.open.de
*
* Supports:
*
* RENUMBER - the #define directive in the current line is evaluated.
* If it doesn't hold a value, 0 is assumed, otherwise it
* is taken as start value. All following #define's will
* be assigned a sequential numbering until a line is
* encountered that does not meet the format: #define NAME
*
* REFERENCE - The word under the cursor or left of it is assumed to
* hold a #define'd value. It is first searched in the
* current text. If it cannot be found, a prefix is
* extracted, if the symbol meets the format PREFIX_NAME
* Then the last occurence of PREFIX_ is searched.
* If the search is unsuccessful still, the corresponding
* includefile is openend and the procedure is redone
* there.
*
* Installation:
*
* - Call 'DoRexx "define.wrx" ACTION' from 'WRITE'
* - put '$Includefile = Myfile.h' somewhere in your code (e.g. in
* comments), if you want an autolookup in your includes
*
*/
arg action
if ~show('P',"WRITE") then
do
say "This script is useless without the WRITE editor!"
exit 0
end
address 'WRITE'
options results
'VERSIONCHECK 40000 "Define.wrx"'
IF RC~=0 THEN DO
exit 10
END
'GetVar (_CurrentID)'
ID = RESULT
'LockWindow' ID
select
when action = "RENUMBER" then call renumber
when action = "REFERENCE" then call reference
otherwise 'MessageOK (Unbekannte Option:' action ')'
end
'LockWindow 0'
exit 0
renumber: procedure
'GetVar (_XPos)' /* get home position */
a.x = RESULT
'GetVar (_YPos)'
a.y = RESULT
'GetVar (_CurrentLine)' /* get line and check syntax */
line = RESULT
if word(line,1) ~= "#define" then
do
'MessageOK (Sorry, this is not a "#define"!)'
return
end
if word(line,2) = "" then
do
'MessageOK (Well, a name would be fine!)'
return
end
init = word(line,3) /* get start value */
if init = "" then init = 0
do until line = "" /* process all valid lines */
idx = wordindex(line,3)
if idx = 0 then line = line init /* create renumbered line */
else do
line = delword(line,3)
line = insert(init,line,idx-1)
end
'FirstInLine'
'DeleteLine' /* kill old line and write new */
'WriteText "'||line||'"'
'Return'
init = init + 1 /* increase number */
'GetVar (_CurrentLine)' /* check next line for validity */
line = RESULT
if word(line,1) ~= "#define" then line = ""
if word(line,2) = "" then line = ""
end
'Goto' a.x a.y
return
reference: procedure EXPOSE ID OldID ret
'GetVar (_XPos)' /* get home position */
a.x = RESULT
'GetVar (_YPos)'
a.y = RESULT
'GetVar (_CurrentWord)' /* get word to reference */
ref = RESULT
do while ref = "RESULT"
CursorLeft 1
if RC ~= 0 then return
'GetVar (_CurrentWord)'
ref = RESULT
end
p = pos("_",ref) /* get prefix */
if p ~= 0 then
do
pre = left(ref,p)
end
else pre = ""
call findref /* seek current file */
if ret = 0 then return
call getincfile /* get inc, if not found */
if ret ~= 0 then
do
'Goto' a.x a.y
return
end
call findref /* and seek in includes */
if OldID ~= 0 then
do
LockWindow OldID
'Goto' a.x a.y
LockWindow ID
end
return
findref: procedure EXPOSE ret ref pre
ret = 0
'Goto 1 1'
'SetVar (_FindString) ('||ref||')'
'Find 0' /* find first occurence */
if RC = 0 then
do
'GetVar (_CurrentLine)'
line = RESULT
if word(line,1) = "#define" then return /* #define must be first, so quit */
end
if pre = "" then /* no prefix => not found */
do
ret = 10
return
end
'Goto 1 1' /* search for prefix */
'SetVar (_FindString) ('||pre||')'
f.x = 0
'Find 0'
do while RC = 0 /* until last occurence */
'GetVar (_CurrentLine)'
line = RESULT
if word(line,1) = "#define" then
do
'GetVar (_XPos)' /* if #define, store positon */
f.x = RESULT
'GetVar (_YPos)'
f.y = RESULT
end
'Find 0'
end
if f.x = 0 then ret=10 /* goto last valid position */
else 'Goto' f.x f.y
return
getincfile: procedure EXPOSE ID OldID ret
'Goto 1 1' /* find locale tag */
'SetVar (_FindString) ($Includefile)'
'Find 0'
if RC = 0 then
do
'GetVar (_CurrentLine)' /* parse it */
line = RESULT
line = substr(line,pos("$Includefile",line))
line = delword(line,1,1)
do i=1 until cnt = 0
ch = substr(line,i,1)
if ((ch = ':') | (ch = '=') | (ch = ' ')) then cnt = 1
else cnt = 0
end
line = substr(line,i)
line = word(line,1)
'GetVar (_CurrentID)' /* store ID */
OldID = RESULT
LockWindow 0 /* we must of course unlock */
'NextED 0' /* file already loaded ? */
file = ""
do while ((RC = 0) & (file ~= line))
'GetVar (_CurrentID)'
ID = RESULT
'GetVar (_File)'
file = RESULT
NextED ID
end
if file = line then
do
LockWindow ID /* lock and activate window */
'Goto 1 1'
'GetVar (_WinMode)'
if ((RESULT = 1) | (RESULT = 2)) then 'Window 0 0 0 0'
end
else do
LockWindow OldID /* if not: get path and open */
'GetVar (_FILEPATH)'
path = RESULT
if right(path,1,':') ~= ':' then path = path || '/'
if ~exists(line) then /* check file existance */
do
if ~exists(path||line) then
do
'MessageOK "Could not open includefile:' line '"'
ret = 10
return
end
line = path||line
end
'NewEd ""' /* open the tagged file */
ID = RESULT
'LockWindow' ID
'Open "'||line||'"'
'Window 0 0 0 0'
end
end
else OldID = 0 /* code: SAME_FILE */
ret = 0
return